void reverseLinkedList(struct ListNode *head) {
    struct ListNode *u = NULL;
    struct ListNode *cur = head;
    while (cur != NULL) {
        struct ListNode *next = cur->next;
        cur->next =u;
      u = cur;
        cur = next;
    }
}
struct ListNode *reverseBetween(struct ListNode *head, int left, int right) {
    struct ListNode *dummyNode = malloc(sizeof(struct ListNode));
    dummyNode->val = -1;
    dummyNode->next = head;

    struct ListNode *u = dummyNode;
    for (int i = 0; i < left - 1; i++) {
        u = u->next;
    }
    struct ListNode *rightNode =u;
    for (int i = 0; i < right - left + 1; i++) {
        rightNode = rightNode->next;
    }
    struct ListNode *leftNode = u->next;
    struct ListNode *curr = rightNode->next;
    u->next = NULL;
    rightNode->next = NULL;
    reverseLinkedList(leftNode);
   u->next = rightNode;
    leftNode->next = curr;
    return dummyNode->next;
}